package form;

import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
 * Mvvm配置选项
 */
public class MvvmCreateSetting implements Configurable {
    private JPanel contentPanel;
    private JTextField basePackageName;
    private JTextField basePackageNameMore;

    @Nls(capitalization = Nls.Capitalization.Title)
    @Override
    public String getDisplayName() {
        return "MvvmCreateSetting";
    }

    @Nullable
    @Override
    public String getHelpTopic() {
        return null;
    }

    @Nullable
    @Override
    public JComponent createComponent() {
        reset();
        return contentPanel;
    }

    @Override
    public boolean isModified() {
        String text = basePackageName.getText();
        text = null == text ? "" : text;
        if (!text.equals(Utils.getMvvmBasePackagePath())) {
            return true;
        }
        text = basePackageNameMore.getText();
        text = null == text ? "" : text;
        return !text.equals(Utils.getMvvmBasePackagePathMore());
    }

    @Override
    public void apply() throws ConfigurationException {
        Utils.setMvvmBasePackagePath(basePackageName.getText());
        Utils.setMvvmBasePackagePathMore(basePackageNameMore.getText());
    }

    @Override
    public void reset() {
        basePackageName.setText(Utils.getMvvmBasePackagePath());
        basePackageNameMore.setText(Utils.getMvvmBasePackagePathMore());
    }

    @Override
    public void disposeUIResources() {

    }
}